home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime vr / vrscript / common files / urlutilities.h < prev    next >
Encoding:
Text File  |  2000-06-23  |  5.2 KB  |  166 lines

  1. //////////
  2. //
  3. //    File:        URLUtilities.h
  4. //
  5. //    Contains:    Some utilities for working with URLs.
  6. //                All utilities start with the prefix "URLUtils_".
  7. //
  8. //    Written by:    Tim Monroe
  9. //
  10. //    Copyright:    © 1998 by Apple Computer, Inc., all rights reserved.
  11. //
  12. //    Change History (most recent first):
  13. //
  14. //       <1>         12/04/98    rtm        first file
  15. //     
  16. //////////
  17.  
  18. #pragma once
  19.  
  20. //////////
  21. //
  22. // header files
  23. //
  24. //////////
  25.  
  26. #ifndef __URLUtilities__
  27. #define __URLUtilities__
  28.  
  29. #ifndef __QTML__
  30. #include <QTML.h>
  31. #endif
  32.  
  33. #ifndef __MOVIES__
  34. #include <Movies.h>
  35. #endif
  36.  
  37. #ifndef __TEXTUTILS__
  38. #include <TextUtils.h>
  39. #endif
  40.  
  41. #include <string.h>
  42. #include <stdlib.h>
  43.  
  44.  
  45. //////////
  46. //
  47. // compiler flags
  48. //
  49. //////////
  50.  
  51. #define USE_EMPTY_LOCALHOST            1                // use "" instead of "localhost" for the local hostname in file URLs
  52.  
  53.  
  54. //////////
  55. //
  56. // constants
  57. //
  58. //////////
  59.  
  60. #define kURLSchemeSeparator            (char)':'        // URL scheme separator
  61. #define kURLPathSeparator            (char)'/'        // URL path separator
  62. #define kURLQuerySeparator            (char)'?'        // URL query separator
  63. #define kURLEscapeCharacter            (char)'%'        // the escape character
  64. #define kURLAuthPrefix                "://"            // the prefix for the authority portion of a URL
  65. #define kURLAuthSuffix                "?/"            // the characters that can terminate the authority portion of a URL
  66. #define kURLPathSuffix                "?"                // the characters that can terminate the path portion of a URL
  67.  
  68. #define kHTTPScheme                    "http"            // the scheme for http URLs
  69. #define kFTPScheme                    "ftp"            // the scheme for ftp URLs
  70. #define kFileScheme                    "file"            // the scheme for file URLs
  71. #define kTelnetScheme                "telnet"        // the scheme for telnet URLs
  72. #define kGopherScheme                "gopher"        // the scheme for gopher URLs
  73.  
  74. #define kLocalhostStr                "localhost"        // the authority portion for local files
  75.  
  76. #define kFilePrefix                    "file://"        // the prefix for file URLs
  77.  
  78.  
  79. #if USE_EMPTY_LOCALHOST
  80. #define kLocalhostAuth                ""                // the authority portion for local files
  81. #else
  82. #define kLocalhostAuth                kLocalhostStr    // the authority portion for local files
  83. #endif
  84.  
  85. #if TARGET_OS_MAC
  86. #define kFilePathSeparator            (char)':'        // on Macintosh, the file path separator is ':'
  87. #elif TARGET_OS_WIN32
  88. #define kFilePathSeparator            (char)'\\'        // on Windows, the file path separator is '\\'
  89. #else
  90. #define kFilePathSeparator            (char)'/'        // on other systems, assume the file path separator is '/'
  91. #endif
  92.  
  93. #if TARGET_OS_MAC
  94. #define kFilePathSepString            ":"                // on Macintosh, the file path separator string is ":"
  95. #elif TARGET_OS_WIN32
  96. #define kFilePathSepString            "\\"            // on Windows, the file path separator string is "\\"
  97. #else
  98. #define kFilePathSepString            "/"                // on other systems, assume the file path separator string is "/"
  99. #endif
  100.  
  101. #define kWinVolumeNameChar            (char)':'        // on Windows, the character that follows volume names in full pathnames
  102. #define kURLVolumeNameChar            (char)'|'        // on Windows, the character that follows volume names in URLs
  103.  
  104. #ifndef MAX_PATH
  105. #define MAX_PATH                    512                // maximum size of a path name
  106. #endif
  107.  
  108.  
  109. //////////
  110. //
  111. // macros
  112. //
  113. //////////
  114.  
  115. #define URLUtils_IsDigit(x)            (((x >= '0') && (x <= '9')) ? 1 : 0)
  116. #define URLUtils_IsUppercase(x)        (((x >= 'A') && (x <= 'Z')) ? 1 : 0)
  117. #define URLUtils_IsLowercase(x)        (((x >= 'a') && (x <= 'z')) ? 1 : 0)
  118. #define URLUtils_ToUppercase(x)        ((URLUtils_IsLowercase(x)) ? x - 'a' + 'A' : x)
  119. #define URLUtils_ToLowercase(x)        ((URLUtils_IsUppercase(x)) ? x + 'a' - 'A' : x)
  120. #define URLUtils_IsAlphabetic(x)    ((URLUtils_IsUppercase(x) || URLUtils_IsLowercase(x)) ? 1 : 0)
  121. #define URLUtils_IsAlphanumeric(x)    ((URLUtils_IsAlphabetic(x) || URLUtils_IsDigit(x)) ? 1 : 0)
  122.  
  123.  
  124. //////////
  125. //
  126. // function prototypes
  127. //
  128. //////////
  129.  
  130. char *                            URLUtils_GetScheme (char *theURL);
  131. char *                            URLUtils_GetAuthority (char *theURL);
  132. char *                            URLUtils_GetPath (char *theURL);
  133. char *                            URLUtils_GetQuery (char *theURL);
  134. static char *                    URLUtils_GetAuthBegin (char *theURL);
  135. static char *                    URLUtils_GetPathBegin (char *theURL);
  136. static char *                    URLUtils_GetQueryBegin (char *theURL);
  137.  
  138. char *                            URLUtils_FullNativePathToURL (char *thePath);
  139. char *                            URLUtils_URLToFullNativePath (char *theURL);
  140. FSSpecPtr                        URLUtils_FullNativePathToFSSpec (char *thePath);
  141. char *                            URLUtils_FSSpecToFullNativePath (const FSSpecPtr theFSSpecPtr);
  142. char *                            URLUtils_FSSpecToURL (const FSSpecPtr theFSSpecPtr);
  143. FSSpecPtr                        URLUtils_URLToFSSpec (char *theURL);
  144. static OSErr                    URLUtils_FSpecGetFullPath (const FSSpecPtr theFSSpecPtr, short *theFullPathLength, Handle *theFullPath);
  145. static OSErr                    URLUtils_LocationFromFullPath (short theFullPathLength, const void *theFullPath, FSSpecPtr theFSSpecPtr);
  146.  
  147. Movie                            URLUtils_NewMovieFromURL (char *theURL, short theFlags, short *theID);
  148. OSErr                            URLUtils_HaveBrowserOpenURL (char *theURL);
  149.  
  150. char *                            URLUtils_GetURLBasename (char *theURL);
  151.  
  152. Boolean                            URLUtils_IsAbsoluteURL (char *theURL);
  153. Boolean                            URLUtils_IsRelativeURL (char *theURL);
  154.  
  155. static Boolean                    URLUtils_IsReservedChar (char theChar);
  156. static Boolean                    URLUtils_IsDelimiterChar (char theChar);
  157. static Boolean                    URLUtils_IsPunctMarkChar (char theChar);
  158. static Boolean                    URLUtils_IsEncodableChar (char theChar);
  159.  
  160. static char *                    URLUtils_EncodeString (char *theString);
  161. static char *                    URLUtils_DecodeString (char *theString);
  162.  
  163.  
  164.  
  165. #endif    // __URLUtilities__
  166.